<?php
class TestOfRequest extends UnitTestCase {

    function testNewEmptyReques() 
    {
        $request = new request();

        // Test empty request
        $this->assertNull($request->app);
        $this->assertNull($request->controller);
        $this->assertNull($request->action);
        $this->assertEqual($request->params,array());
        $this->assertEqual($request->method,'GET');

        $response = $request->process();
        $this->assertEqual($response->action,'notfound');
    }

    function testNewRequest() 
    {
        $request = new request('myapp','mycontroller','myaction',
            array('p1'=>'1','p2'=>'2'),'POST');

        $this->assertEqual($request->app,'myapp');
        $this->assertEqual($request->controller,'mycontroller');
        $this->assertEqual($request->action,'myaction');
        $this->assertEqual($request->params['p1'],'1');
        $this->assertEqual($request->params['p2'],'2');
        $this->assertEqual($request->method,'POST');

        $response = $request->process();
        $this->assertEqual($response->action,'notfound');
    }

    function testProcessRequest() 
    {
        $request = new request('sbook','main','index');

        $this->assertTrue(file_exists(APPS.'sbook'));
        $response = $request->process();
        $this->assertTrue(defined('THISAPP'));
        $this->assertEqual(THISAPP,'sbook');
        $this->assertTrue(defined('APP_PATH'));
        $this->assertTrue(defined('CONTROLLERS'));
        $this->assertTrue(defined('APPLIBS'));
        $this->assertTrue(defined('PUBLIC'));
        $this->assertTrue(defined('VIEWS'));
        $this->assertEqual($response->action,'ok');
    }
}
?>
